<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT, Blog, JAVA,Spring,Mysql,Quartz,Python,程序员" />





  <link rel="alternate" href="https://my.oschina.net/giegie/rss" title="Gie的博客" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="Log4j有三个主要的组件：Loggers(记录器)，Appenders (输出源)和Layouts(布局)。这里可简单理解为日志类别，日志要输出的地方和日志以何种形式输出。综合使用这三个组件可以轻松地记录信息的类型和级别，并可以在运行时控制日志输出的样式和位置。
LoggerLoggers组件被分为五个级别：

DEBUG
INFO
WARN
ERROR
FATAL各个级别的顺序是这样那个的：">
<meta property="og:type" content="article">
<meta property="og:title" content="【日志处理】log4j配置学习总结">
<meta property="og:url" content="https://jieblog.github.io/2017/02/16/【日志处理】log4j配置学习总结/index.html">
<meta property="og:site_name" content="Gie的博客">
<meta property="og:description" content="Log4j有三个主要的组件：Loggers(记录器)，Appenders (输出源)和Layouts(布局)。这里可简单理解为日志类别，日志要输出的地方和日志以何种形式输出。综合使用这三个组件可以轻松地记录信息的类型和级别，并可以在运行时控制日志输出的样式和位置。
LoggerLoggers组件被分为五个级别：

DEBUG
INFO
WARN
ERROR
FATAL各个级别的顺序是这样那个的：">
<meta property="og:updated_time" content="2017-02-23T06:09:23.794Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【日志处理】log4j配置学习总结">
<meta name="twitter:description" content="Log4j有三个主要的组件：Loggers(记录器)，Appenders (输出源)和Layouts(布局)。这里可简单理解为日志类别，日志要输出的地方和日志以何种形式输出。综合使用这三个组件可以轻松地记录信息的类型和级别，并可以在运行时控制日志输出的样式和位置。
LoggerLoggers组件被分为五个级别：

DEBUG
INFO
WARN
ERROR
FATAL各个级别的顺序是这样那个的：">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '75HUY04HZY',
      apiKey: 'c215d1b4c97f100bad332f84e968d70a',
      indexName: 'qq154987607',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://jieblog.github.io/2017/02/16/【日志处理】log4j配置学习总结/"/>





  <meta name="baidu-site-verification" content="cKXv4cbRZc" />
  <meta name="google-site-verification" content="05Vxc1yd7lC2F1bxwmmbQkfP-rZgvPLTqufHSzImPcM" />
  <title> 【日志处理】log4j配置学习总结 | Gie的博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?7e8381cb6c39db6048492ff2e52234cb";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Gie的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">为人瓜而不皮 一身正气</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="https://jieblog.github.io/2017/02/16/【日志处理】log4j配置学习总结/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="Gie">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/logo.png">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Gie的博客">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Gie的博客" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
            
            
              
                【日志处理】log4j配置学习总结
              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-16T00:00:00+08:00">
                2017-02-16
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/JAVAEE/" itemprop="url" rel="index">
                    <span itemprop="name">JAVAEE</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>Log4j有三个主要的组件：Loggers(记录器)，Appenders (输出源)和Layouts(布局)。这里可简单理解为日志类别，日志要输出的地方和日志以何种形式输出。综合使用这三个组件可以轻松地记录信息的类型和级别，并可以在运行时控制日志输出的样式和位置。</p>
<h2 id="Logger"><a href="#Logger" class="headerlink" title="Logger"></a>Logger</h2><p>Loggers组件被分为五个级别：</p>
<ul>
<li>DEBUG</li>
<li>INFO</li>
<li>WARN</li>
<li>ERROR</li>
<li><p>FATAL<br>各个级别的顺序是这样那个的：</p>
<p>  DEBUG &lt; INFO &lt; WARN &lt; ERROR &lt; FATAL</p>
</li>
</ul>
<p><strong>可以简单地理解为级别越大越重要。</strong>  </p>
<p>Log4j有一个规则：只输出级别不低于设定级别的日志信息，假设Loggers级别设定为INFO，则INFO、WARN、ERROR和FATAL级别的日志信息都会输出，而级别比INFO低的DEBUG则不会输出。</p>
<h2 id="Appender"><a href="#Appender" class="headerlink" title="Appender"></a>Appender</h2><p>Appender用来规定日志输出的目的地是哪里，可以是控制台，文件，数据库等等。<br>常见的Appender有以下几种：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">org.apache.log4j.ConsoleAppender（控制台）</div><div class="line">org.apache.log4j.FileAppender（文件）</div><div class="line">org.apache.log4j.DailyRollingFileAppender（每天产生一个日志文件）</div><div class="line">org.apache.log4j.RollingFileAppender（文件大于配置的时候产生一个新的文件）</div><div class="line">org.apache.log4j.WriterAppender（将日志信息以流格式发送到任意指定的地方）</div></pre></td></tr></table></figure>
<p>在配置文件中是这样配置的：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">log4j.appender.appenderName = className</div><div class="line">log4j.appender.appenderName.Option1 = value1</div><div class="line">…</div><div class="line">log4j.appender.appenderName.OptionN = valueN</div></pre></td></tr></table></figure>
<p>其中appenderName是Appender的名字，可以随意起，只要满足命名规范就行，Option1，Option2，…，OptionN是这个appender的各种属性。</p>
<h2 id="Layout"><a href="#Layout" class="headerlink" title="Layout"></a>Layout</h2><p>Layout用来规定日志是以什么样的格式输出，需要输出哪些信息。Layout提供四种日志输出样式，如根据HTML样式、自由指定样式、包含日志级别与信息的样式和包含日志时间、线程、类别等信息的样式。<br>常见的Layout如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">org.apache.log4j.HTMLLayout（以HTML表格形式布局）</div><div class="line">org.apache.log4j.PatternLayout（可以灵活地指定布局模式）</div><div class="line">org.apache.log4j.SimpleLayout（包含日志信息的级别和信息字符串）</div><div class="line">org.apache.log4j.TTCCLayout（包含日志产生的时间、线程、类别等信息）</div></pre></td></tr></table></figure>
<p>在配置文件中这样配置的：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">log4j.appender.appenderName.layout =className</div><div class="line">log4j.appender.appenderName.layout.Option1 = value1</div><div class="line">…</div><div class="line">log4j.appender.appenderName.layout.OptionN = valueN</div></pre></td></tr></table></figure>
<p>含义和Appender的配置是一样的，就不另作解释了。</p>
<h2 id="配置详解"><a href="#配置详解" class="headerlink" title="配置详解"></a>配置详解</h2><p>在实际应用中，要使Log4j在系统中运行须事先设定配置文件。配置文件事实上也就是对Logger、Appender及Layout进行相应设定。 Log4j支持两种配置文件格式，一种是XML格式的文件，一种是properties属性文件。下面以properties属性文件为例介绍。</p>
<h3 id="配置Logger"><a href="#配置Logger" class="headerlink" title="配置Logger"></a>配置Logger</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">log4j.rootLogger = [ level ] , appenderName1, appenderName2, …</div><div class="line">log4j.additivity.org.apache=false （不重复）</div></pre></td></tr></table></figure>
<p>level ：设定日志记录的最低级别，可设的值有OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL或者自定义的级别，Log4j建议只使用中间四个级别<br>appenderName：就是指定日志信息要输出到哪里。可以同时指定多个输出目的地，用逗号隔开。  </p>
<p>例如：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">log4j.rootLogger＝INFO,A1,B2,C3</div></pre></td></tr></table></figure></p>
<h3 id="配置Appender"><a href="#配置Appender" class="headerlink" title="配置Appender"></a>配置Appender</h3><p>log4j.appender.appenderName = className</p>
<p>appenderName: Appender的名字，自定义，在log4j.rootLogger设置中使用；<br>常用的Appender的className如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">org.apache.log4j.ConsoleAppender（控制台）</div><div class="line">org.apache.log4j.FileAppender（文件）</div><div class="line">org.apache.log4j.DailyRollingFileAppender（每天产生一个日志文件）</div><div class="line">org.apache.log4j.RollingFileAppender（文件大小到达指定尺寸的时候产生一个新的文件）</div><div class="line">org.apache.log4j.WriterAppender</div><div class="line">Threshold=WARN：指定日志信息的最输出级别  </div><div class="line">ImmediateFlush=true：表示所有消息都会被立即输出</div><div class="line">Target=System.err：默认值是System.out。</div></pre></td></tr></table></figure>
<h4 id="FileAppender选项"><a href="#FileAppender选项" class="headerlink" title="FileAppender选项"></a>FileAppender选项</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">Threshold=WARN：指定日志信息的最低输出级别，默认为DEBUG。</div><div class="line">ImmediateFlush=true：表示所有消息都会被立即输出，设为false则不输出，默认值是true。</div><div class="line">Append=false：true表示消息增加到指定文件中，false则将消息覆盖指定的文件内容，默认值是true。</div><div class="line">File=D:/logs/logging.log4j：指定消息输出到logging.log4j文件中</div></pre></td></tr></table></figure>
<h4 id="DailyRollingFileAppender选项"><a href="#DailyRollingFileAppender选项" class="headerlink" title="DailyRollingFileAppender选项"></a>DailyRollingFileAppender选项</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">Threshold=WARN：指定日志信息的最低输出级别，默认为DEBUG。</div><div class="line">ImmediateFlush=true：表示所有消息都会被立即输出，设为false则不输出，默认值是true。</div><div class="line">Append=false：true表示消息增加到指定文件中，false则将消息覆盖指定的文件内容，默认值是true。</div><div class="line">File=D:/logs/logging.log4j：指定当前消息输出到logging.log4j文件中。</div><div class="line">DatePattern=’.’yyyy-MM：每月产生一个新的日志文件。</div></pre></td></tr></table></figure>
<p>另外，也可以指定按周、天、时、分等来滚动日志文件，对应的格式如下：<br>‘.’yyyy-MM：每月<br>‘.’yyyy-ww：每周<br>‘.’yyyy-MM-dd：每天<br>‘.’yyyy-MM-dd-a：每天两次<br>‘.’yyyy-MM-dd-HH：每小时<br>‘.’yyyy-MM-dd-HH-mm：每分钟  </p>
<h4 id="RollingFileAppender选项"><a href="#RollingFileAppender选项" class="headerlink" title="RollingFileAppender选项"></a>RollingFileAppender选项</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">Threshold=WARN：指定日志信息的最低输出级别，默认为DEBUG。</div><div class="line">ImmediateFlush=true：表示所有消息都会被立即输出，设为false则不输出，默认值是true。</div><div class="line">Append=false：true表示消息增加到指定文件中，false则将消息覆盖指定的文件内容，默认值是true。</div><div class="line">File=D:/logs/logging.log4j：指定消息输出到logging.log4j文件中。</div><div class="line">MaxFileSize=100KB：后缀可以是KB, MB 或者GB**。。</div><div class="line">MaxBackupIndex=2：指定可以产生的滚动文件的最大数</div><div class="line">配置Layout</div></pre></td></tr></table></figure>
<h4 id="log4j-appender-appenderName-layout-className"><a href="#log4j-appender-appenderName-layout-className" class="headerlink" title="log4j.appender.appenderName.layout=className"></a>log4j.appender.appenderName.layout=className</h4><p>常见的className如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">org.apache.log4j.HTMLLayout（以HTML表格形式布局）</div><div class="line">org.apache.log4j.PatternLayout（可以灵活地指定布局模式）</div><div class="line">org.apache.log4j.SimpleLayout（包含日志信息的级别和信息字符串）</div><div class="line">org.apache.log4j.TTCCLayout（包含日志产生的时间、线程、类别等等信息）</div></pre></td></tr></table></figure>
<p>HTMLLayout选项</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line">LocationInfo=true：输出java文件名称和行号，默认值是false。</div><div class="line">Title=My Logging： 默认值是Log4J Log Messages。</div><div class="line">PatternLayout选项</div><div class="line">ConversionPattern=%m%n：设定以怎样的格式显示消息。</div><div class="line">各种格式化说明如下：</div><div class="line"></div><div class="line">%p：输出日志信息的优先级，即DEBUG，INFO，WARN，ERROR，FATAL。</div><div class="line">%d：输出日志时间点的日期或时间，默认格式为ISO8601，也可以在其后指定格式，如：%d&#123;yyyy/MM/dd HH:mm:ss,SSS&#125;。</div><div class="line">%r：输出自应用程序启动到输出该log信息耗费的毫秒数。</div><div class="line">%t：输出产生该日志事件的线程名。</div><div class="line">%l：输出日志事件的发生位置，相当于%c.%M(%F:%L)的组合，包括类全名、方法、文件名以及在代码中的行数。例如：test.TestLog4j.main(TestLog4j.java:10)。</div><div class="line">%c：输出日志信息所属的类目，通常就是所在类的全名。</div><div class="line">%M：输出产生日志信息的方法名。</div><div class="line">%F：输出日志消息产生时所在的文件名称。</div><div class="line">%L:：输出代码中的行号。</div><div class="line">%m:：输出代码中指定的具体日志信息。</div><div class="line">%n：输出一个回车换行符，Windows平台为”\r\n”，Unix平台为”\n”。</div><div class="line">%x：输出和当前线程相关联的NDC(嵌套诊断环境)，尤其用到像java servlets这样的多客户多线程的应用中。</div><div class="line">%%：输出一个”%”字符。</div></pre></td></tr></table></figure>
<h3 id="附"><a href="#附" class="headerlink" title="附"></a>附</h3><p>一段简单的log4j配置备用:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">### set log levels ###</div><div class="line">log4j.rootLogger = debug,stdout,D,E</div><div class="line"></div><div class="line">### 输出到控制台 ###</div><div class="line">log4j.appender.stdout = org.apache.log4j.ConsoleAppender</div><div class="line">log4j.appender.stdout.Target = System.out</div><div class="line">log4j.appender.stdout.layout = org.apache.log4j.PatternLayout</div><div class="line">log4j.appender.stdout.layout.ConversionPattern =  %-d&#123;yyyy-MM-dd HH:mm:ss&#125;  [ %t:%r ] - [ %p ]  %m%n</div><div class="line"></div><div class="line">### 输出到日志文件 ###</div><div class="line">log4j.appender.D = org.apache.log4j.DailyRollingFileAppender</div><div class="line">log4j.appender.D.File = logs/log.log</div><div class="line">log4j.appender.D.Append = true</div><div class="line">log4j.appender.D.Threshold = INFO</div><div class="line">log4j.appender.D.layout = org.apache.log4j.PatternLayout</div><div class="line">log4j.appender.D.layout.ConversionPattern = %-d&#123;yyyy-MM-dd HH:mm:ss&#125;  [ %t:%r ] - [ %p ]  %m%n</div><div class="line">log4j.appender.D.DatePattern = &apos;.&apos;yyyy-MM-dd</div><div class="line"></div><div class="line">### 保存异常信息到单独文件 ###</div><div class="line">log4j.appender.E = org.apache.log4j.DailyRollingFileAppender</div><div class="line">log4j.appender.E.File = logs/error.log</div><div class="line">log4j.appender.E.Append = true</div><div class="line">log4j.appender.E.Threshold = ERROR</div><div class="line">log4j.appender.E.layout = org.apache.log4j.PatternLayout</div><div class="line">log4j.appender.E.DatePattern = &apos;.&apos;yyyy-MM-dd-HH-mm</div><div class="line">log4j.appender.E.layout.ConversionPattern = %-d&#123;yyyy-MM-dd HH:mm:ss&#125;  [ %t:%r ] - [ %p ]  %m%n</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/02/15/ArrayList foreach 循环里进行元素的 remove add 操作有什么现象/" rel="next" title="ArrayList foreach 循环里进行元素的 remove add 操作有什么现象">
                <i class="fa fa-chevron-left"></i> ArrayList foreach 循环里进行元素的 remove add 操作有什么现象
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/02/21/Quartz依赖数据库表/" rel="prev" title="Quartz依赖数据库表">
                Quartz依赖数据库表 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8yNzgyMS80Mzk3"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/logo.png"
               alt="Gie" />
          <p class="site-author-name" itemprop="name">Gie</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
           
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">94</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
        </nav>

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/jieblog" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://git.oschina.net/log4j" target="_blank" title="GitOsc">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  GitOsc
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/u/3911368554" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  Weibo
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="wangiegieg@gmail.com" target="_blank" title="Email">
                  
                    <i class="fa fa-fw fa-google"></i>
                  
                  Email
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Logger"><span class="nav-number">1.</span> <span class="nav-text">Logger</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Appender"><span class="nav-number">2.</span> <span class="nav-text">Appender</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Layout"><span class="nav-number">3.</span> <span class="nav-text">Layout</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#配置详解"><span class="nav-number">4.</span> <span class="nav-text">配置详解</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#配置Logger"><span class="nav-number">4.1.</span> <span class="nav-text">配置Logger</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置Appender"><span class="nav-number">4.2.</span> <span class="nav-text">配置Appender</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#FileAppender选项"><span class="nav-number">4.2.1.</span> <span class="nav-text">FileAppender选项</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#DailyRollingFileAppender选项"><span class="nav-number">4.2.2.</span> <span class="nav-text">DailyRollingFileAppender选项</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#RollingFileAppender选项"><span class="nav-number">4.2.3.</span> <span class="nav-text">RollingFileAppender选项</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#log4j-appender-appenderName-layout-className"><span class="nav-number">4.2.4.</span> <span class="nav-text">log4j.appender.appenderName.layout=className</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#附"><span class="nav-number">4.3.</span> <span class="nav-text">附</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Gie</span>
</div>



        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  

  
    <span class="site-pv">本站总访问量<span class="busuanzi-value" id="busuanzi_value_site_pv"></span>次</span>
  

</div>



        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  



  
  

  

  

  

  

  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.0"></script>



  

</body>
</html>
